<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" 
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core">

<ui:composition template="/pages/layout.xhtml">
	<ui:define name="conteudo">
		<h3>Minhas Contas</h3>
		
		<h:commandLink action="#{contasMBean.novo}" value="Cadastrar"/>
		
		<br/><br/>
		
		<table>
			<tr>
				<td>
					Mês: <h:inputText value="#{contasMBean.mes}" size="2"/>
				</td>
				<td>
					Ano: <h:inputText value="#{contasMBean.ano}" size="4"/>
				</td>
				<td>
					<h:commandButton value="Consultar" action="#{contasMBean.consultar}"/>
				</td>
			</tr>
		</table>
		
		<br/>
		
		<h:panelGroup layout="block" rendered="#{not empty contasMBean.contas}">
			<h:dataTable value="#{contasMBean.listagem}" var="conta" cellspacing="10" border="1"> 
				<h:column>
					<f:facet name="header">
						<h:outputText value="Data"/>
					</f:facet>
					<h:outputText value="#{conta.dataVencimento}">
						<f:convertDateTime pattern="dd/MM/yyyy"/>
					</h:outputText>
				</h:column>
				
				<h:column>
					<f:facet name="header">
						<h:outputText value="Descrição"/>
					</f:facet>
					<h:outputText value="#{conta.descricao}"/>
				</h:column>
				
				<h:column>
					<f:facet name="header">
						<h:outputText value="Categoria"/>
					</f:facet>
					<h:outputText value="#{conta.categoria.descricao}"/>
				</h:column>
				
				<h:column>
					<f:facet name="header">
						<h:outputText value="Valor"/>
					</f:facet>
					<h:outputText value="#{conta.valor}"/>
				</h:column>
				
				<h:column>
					<f:facet name="header">
						<h:outputText value="Tipo"/>
					</f:facet>
					<h:outputText value="#{conta.tipo.descricao}"/>
				</h:column>
				
				<h:column>
					<f:facet name="header">
						<h:outputText value="Situação"/>
					</f:facet>
					<h:outputText value="#{conta.situacao.descricao}"/>
				</h:column>
			
				<h:column>
					<h:commandLink action="#{contasMBean.alterar}" value="Alterar" />
				</h:column>
			
				<h:column>
					<h:commandLink action="#{contasMBean.remover}" value="Remover" onclick="return confirm('Deseja realmente remover esse registro?')"/>
				</h:column>
			</h:dataTable>
			<br/>
			<h:panelGroup layout="block" id="valorTotal">
				Total:  <b><h:outputText value="#{contasMBean.valorTotal}"/></b>
			</h:panelGroup>
		</h:panelGroup>
	</ui:define>
</ui:composition>

</html>